﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.Columns;

namespace MiniKsiegowosc
{
    public partial class Form1 : Form
    {
        DataTable dt = new DataTable();
        private void InitData()
        {
            dataSet1.Clear();
            for(int i = 0;i<10;i++)
            dataSet1.ViewTab.AddViewTabRow("CODE" + i, "row "+i, "inna " + i, " P");
            for (int i=0; i < 10; i++)
            {
                dataSet1.TreeTab.AddTreeTabRow("Tree" + i, "Tree name " + i, "", "Inna " + i);
            }
            for (int i=0; i < 4; i++)
            {
                dataSet1.TreeTab.AddTreeTabRow("Tree_1" + i, "Tree name _1" + i, "Tree1", "Inna " + i);
                dataSet1.TreeTab.AddTreeTabRow("Tree_2" + i, "Tree name _2" + i, "Tree2", "Inna " + i);
                dataSet1.TreeTab.AddTreeTabRow("Tree_11" + i, "Tree name _11" + i, "Tree11", "Inna " + i);
            }
            repositoryItemMultiLookUpEdit1.AddGridTab(dataSet1.ViewTab, "CODE", "CODE", "", "V", "View Table");
            repositoryItemMultiLookUpEdit1.AddTreeTab(dataSet1.TreeTab, "CODE", "CODE", "PARENT", "", "T", "Tree table");

            multiLookUpEdit1.Properties.AddGridTab(dataSet1.ViewTab, "CODE", "CODE", "", "V", "View Table");
            multiLookUpEdit1.Properties.AddTreeTab(dataSet1.TreeTab, "CODE", "CODE", "PARENT", "", "T", "Tree table");
        }

        public Form1()
        {
            InitializeComponent();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Nazwa");
            dt.Columns.Add("PARENT", typeof(int));
            dt.Rows.Add(1, " opt 1");
            dt.Rows.Add(11, " opt 11",1 );
            dt.Rows.Add(12, " opt 12",1);
            dt.Rows.Add(2, " opt 2");
            dt.Rows.Add(21, " opt 21",2);
            dt.Rows.Add(22, " opt 22",2);
            dt.Rows.Add(23, " opt 23",2);
            dt.Rows.Add(231, " opt 231",23);

            dt.Rows.Add(3, " opt 3");
            dt.Rows.Add(31, " opt 31",3);
            dt.Rows.Add(312, " opt 312",31);
            dt.Rows.Add(3123, " opt 3123",312);
            dt.Rows.Add(4, " opt 4");

            this.treeLookUpEdit1.Properties.TreeList.BeginInit();
           
            treeLookUpEdit1.Properties.KeyFieldName = "ID";
            treeLookUpEdit1.Properties.ParentFieldName = "PARENT";
            // this.treeLookUpEdit1.Properties.TreeList.Columns.Add().FieldName = "ID";
           // this.treeLookUpEdit1.Properties.TreeList.Columns.Add().FieldName = "Nazwa";
           // this.treeLookUpEdit1.Properties.TreeList.Columns.Add().FieldName = "PARENT";
           // foreach (TreeListColumn c in this.treeLookUpEdit1.Properties.TreeList.Columns)
           //     c.Visible = true;
            this.treeLookUpEdit1.Properties.TreeList.EndInit();
            this.treeLookUpEdit1.Properties.MultiSelect = true;
            this.treeLookUpEdit1.Properties.DisplayMember = "Nazwa";
            this.treeLookUpEdit1.Properties.DataSource = dt;
        }

        private void treeLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            textEdit1.Text = treeLookUpEdit1.EditValue.AsString();
        }

        private void multiLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            textEdit1.Text = multiLookUpEdit1.EditValue.AsString();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            InitData();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            dataSet1.DataSource.WriteXml(Application.StartupPath + "\\DS.XML");
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            dataSet1.DataSource.ReadXml(Application.StartupPath + "\\DS.XML");
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
                gridView1.DeleteSelectedRows();
        }
    }
}
